﻿using System.Runtime.Caching;

namespace Infrastructure.Storage
{
    public class MemoryCacheStorageAdapter : ICacheStorage
    {
        private static readonly ObjectCache Cache = MemoryCache.Default;

        public void Add(string key, object data)
        {
            var cacheItemPolicy = new CacheItemPolicy();

            Cache.Add(key, data, cacheItemPolicy); 
        }

        public void Remove(string key)
        {
            Cache.Remove(key);
        }

        public T Get<T>(string key) where T : class
        {
            try
            {
                return (T)Cache[key];
            }
            catch
            {
                return null;
            }

        }
    }
}